package de.kimera.model;

import java.text.SimpleDateFormat;
import java.util.Date;

import de.kimera.api.IShift;
import de.kimera.api.ITableOfHours;
import de.kimera.utils.Utils;

public class Shift implements IShift{
	private Date beginning;
	private Date end;
	private ITableOfHours tableOfHours;
	
	public Shift(Date beginning, Date end) {
		this.beginning = beginning;
		this.end = end;
	}

	//GETTERs
	@Override
	public ITableOfHours getTableOfHours() {
		return tableOfHours;
	}

	public String getDateString(){/**returns the day part of the beginning date*/
		SimpleDateFormat formatter = new SimpleDateFormat(Utils.DATE_FORMAT);
		return formatter.format(beginning);
	}
	
	public String getBeginnString(){/**returns the hour:minute part of the beginning date*/
		SimpleDateFormat formatter = new SimpleDateFormat(Utils.TIME_FORMAT);
		return formatter.format(beginning);
	}
	
	public String getEndString(){/**returns the hour:minute part of the end date*/
		SimpleDateFormat formatter = new SimpleDateFormat(Utils.TIME_FORMAT);
		return formatter.format(end);
	}
	
	@Override
	public void setTableOfHours(ITableOfHours tableOfHours) {
		this.tableOfHours = tableOfHours;		
	}
	
	//OTHERs
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((beginning == null) ? 0 : beginning.hashCode());
		result = prime * result + ((end == null) ? 0 : end.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Shift other = (Shift) obj;
		if (beginning == null) {
			if (other.beginning != null)
				return false;
		} else if (!beginning.equals(other.beginning))
			return false;
		if (end == null) {
			if (other.end != null)
				return false;
		} else if (!end.equals(other.end))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Beginning=" + beginning + ", End=" + end + "\n";
	}
}
